const path = require('path')
const webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin');
const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV)
// dll文件存放的目录
const dllPath = "dist/dll/vendor";
module.exports = {
    mode:"production",
    entry: {
        // 需要提取的库文件
        vue:["vue","vue-router"],
        axios:["axios"],
        swiper:["swiper"]
    },
    output: {
        path: path.join(__dirname, dllPath),
        filename: '[name].dll.js',
        library: '[name]_[hash]',
        // libraryTarget: 'umd',
    },
    plugins: [
        // 清除之前的dll文件
        new CleanWebpackPlugin(['*.*'], {
            root: path.join(__dirname, dllPath)
        }),
        // 设置环境变量
        // new webpack.DefinePlugin({
        //     'process.env': {
        //         NODE_ENV: 'production'
        //     }
        // }),
        // manifest.json 描述动态链接库包含了哪些内容
        new webpack.DllPlugin({
            path: path.join(__dirname, dllPath, '[name]-manifest.json'),
            // 保持与 output.library 中名称一致
            name: '[name]_[hash]',
            context:process.cwd(),
        })
    ]
}